package leetcode.秋招.小马智行;

import java.util.Scanner;

/**
 * @author ：zsy
 * @date ：Created 2021/8/28 14:47
 * @description：
 */
public class Main {
    static int ans = 0;
    static int e;
    static int em;
    static int m;
    static int mh;
    static int h;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int i = 0; i < T; i++) {
            e = in.nextInt();
            em = in.nextInt();
            m = in.nextInt();
            mh = in.nextInt();
            h = in.nextInt();
            if ((e == 0 && em == 0) || (mh == 0 && h == 0)) {
                System.out.println(0);
            } else {
                dfs(0);
                System.out.println(ans);
            }
        }
    }

    private static void dfs(int i) {
        if (i == 3) {
            ans++;
            return;
        }
        if (i == 0) {
            while (e != 0 || em != 0) {
                if (e != 0) {
                    e--;
                    dfs(i + 1);
                } else if (em != 0) {
                    em--;
                    dfs(i + 1);
                }
            }
        } else if (i == 1) {
                if (em != 0) {
                    em--;
                    dfs(i + 1);
                } else if (m != 0) {
                    m--;
                    dfs(i + 1);
                } else if (mh != 0) {
                    mh--;
                    dfs(i + 1);
                }

        } else if (i == 2) {
                if (h != 0) {
                    h--;
                    dfs(i + 1);
                }
        }
    }
}
